/*物料模型 可移动表格*/
var tbsourcefactoryColresizeEventForTwo={
	index_y:1,//统计列个数	
	index_x_no: 1,//计算行号
	table_source_arr : new Array(),//列对应下面有几个小列
	table_source_type_arr : function(){return $(".source_factory_colresizeable_for_two").find('[name="order_s_material_type"]').map(function(){return $(this).text()}).get()},
	//uniqueId_arr:new Array(),
    table_source_data : function(){return JSON.parse(getLocalInfo("table_source_factory_colresize_for_two.html"))},
	last_uniqueId_for_template_card:"",
	init:function(){
		this.source_factory_add_y_first(this.table_source_data().special_val,1);//默认第一个原材料
		if($(".source_factory_colresizeable_for_two").length>0){
			$(".source_factory_colresizeable_for_two").colResizable({
				liveDrag:true, 
				gripInnerHtml:"<div class='grip'></div>", 
				draggingClass:"dragging", 
	            resizeMode:'fit',
	            onResize:function(e){
	            	var table = $(e.currentTarget); //reference to the resized table
	            	console.info("resize");
	            },
	            onDrag:function(e){
	            	var table = $(e.currentTarget); //reference to the resized table
	            	console.info("drap");
	            }
	        });
			$(".source_factory_colresizeable_for_two").unbind("click");
			$(".source_factory_colresizeable_for_two").bind("click",function(){
				$(document).resize();
				if($(".source_factory_colresizeable_for_two").find("tr:first").find("td").eq(0).width()<5){
					$(".source_factory_colresizeable_for_two").colResizable({
						disable:true
			        });
					$(".source_factory_colresizeable_for_two").colResizable({
						disable:false
			        });
					tbsourcefactoryColresizeEventForTwo.reload_first_w();
				}
			})
		}
		//自行增加行保持和大组件一一致
		tbsourcefactoryColresizeEventForTwo.source_factory_add_x();
	},
	table_source_arr_for_temp:function(){
		var table_source_arr = localStorage.getItem("temp_info_table_source_arr_for_two");
        var table_source_line_total =  localStorage.getItem("table_source_line_total_for_two");
        if(table_source_arr!=null&&table_source_arr!="undefined"&&(window.location.href.indexOf("template.html")>0||window.location.href.indexOf("audit.html")>0)){
            //alert(table_source_arr_str);
            this.table_source_arr = table_source_arr.split(",");
            if(table_source_arr==""){
            	this.table_source_arr =new Array();
        	}
            this.index_y=this.table_source_arr.length;
            this.index_x_no=table_source_line_total;
        }
	},
	initReloadData:function(){
		this.index_y=1;
		this.index_x_no=1;
		this.table_source_arr=new Array();
		//this.table_source_type_arr=new Array();
	},
	bindEvent:function(){
		//排除订单数 投料数
        //.not("[name='order_s_feed_total']").not("[name='order_s_order_total']")
    	//原材料仓contenteditable='true'
		$(".source_factory_colresizeable_for_two").find(".source_factory_colresizeable_td").find("[contenteditable='true']").unbind("click.editable");
        
		$(".source_factory_colresizeable_for_two").find(".source_factory_colresizeable_td").find("[contenteditable='true']").bind("click.editable",function(e){
			var name=$(this).attr("name");
			var uniqueid =$(this).parent().attr("uniqueid");
			var order_s_material_house = $("[uniqueid='"+uniqueid+"']").find("[name='order_s_material_house']").val();
			if(order_s_material_house=="3"){
				return;
			}
			//默认色号 色号 描述 规格型号可以弹dialog 不排除order_s_material_description
			if("order_s_material_color,order_s_material_model,order_s_material_name,order_s_material_description".indexOf(name)<0){
				return;
			}
			var uniqueid = $(this).parent().attr("uniqueid");
			var td_uniqueid = $(this).parent().attr("td_uniqueid");
			var tr_uniqueid = $(this).parent().parent().attr("tr_uniqueid");
			var material_source_type = $("[uniqueid='"+uniqueid+"']").find("[name='order_s_material_type']").text();
			var isreadcolor = $("[uniqueid='"+uniqueid+"']").find("[name='order_s_isReadColor']").val();
            $('div#easyui_dialog_source').dialog({
                modal: true,
                title: '请选择',
                width: "700",
                height: "400",
                closed: false,
                border:false,
                cache: false,
                resizable: true,
                content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='source_factory_colresize_dialog_for_two.html?material_source_type="+material_source_type+"&uniqueid="+uniqueid+"&td_uniqueid="+td_uniqueid+"&tr_uniqueid="+tr_uniqueid+"&ev="+name+"&order_s_material_house="+order_s_material_house+"&isreadcolor="+isreadcolor+"'></iframe>",
                onClose : function() {  
                	tbsourcefactoryColresizeEventForTwo.destroydialog();
                }
            });
        });
		//开料方式增加点击选择功能
		$("[name='order_s_klfs_way']").unbind("click");
		$("[name='order_s_klfs_way']").bind("click",function(){
			var uniqueid = $(this).parent().attr("uniqueid");
			var td_uniqueid = $(this).parent().attr("td_uniqueid");
			var tr_uniqueid = $(this).parent().parent().attr("tr_uniqueid");
			var material_source_type = $("[uniqueid='"+uniqueid+"']").find("[name='order_s_material_type']").text();
			var name=$(this).attr("name");
			$('div#easyui_dialog_source').dialog({
                modal: true,
                title: '请选择',
                width: "400",
                height: "300",
                closed: false,
                border:false,
                cache: false,
                content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='klfs_dialog.html?material_source_type="+material_source_type+"&uniqueid="+uniqueid+"&td_uniqueid="+td_uniqueid+"&tr_uniqueid="+tr_uniqueid+"&ev="+name+"'></iframe>",
                onClose : function() {  
                	tbsourcefactoryColresizeEventForTwo.destroydialog();
                }
            });
		})
		//用料条数
		$("[name='order_s_ylts_total']").unbind("blur");
	    $("[name='order_s_ylts_total']").bind("blur",function(){
	    	$(this).text($(this).text().replace(/[^\d.]/g,''));
	    })
	    //每条料可开数
		/**$("[name='order_s_mtlkt_total']").unbind("blur");
	    $("[name='order_s_mtlkt_total']").bind("blur",function(){
	    	$(this).text($(this).text().replace(/[^\d.]/g,''));
	    })**/
		//绑定工艺事件
        Util_artsEvent.bindEvent();
	    //大货时间时间
	    this.bindDhDateEvent();
	},
	destroydialog:function(){
        $("div#easyui_dialog_source").dialog('destroy');  
        $("body").append("<div id='easyui_dialog_source'></div>");
    },
    /*增加列 放在哪个物料前面*/
    source_factory_add_y_sort_material_type:function(colspan,defaulthouse){
    	//判断是否勾选 
    	//需要排序自定义
    	if($("[name='checkbox_materialTypeSort']").get(0).checked) {
    	  //获取放在哪个物料之前
    	  var selectStr="<select onchange=tbsourcefactoryColresizeEventForTwo.select_sort_material_type(this,"+colspan+","+defaulthouse+")><option value=''>请选择</option>";
    	  for(var i=0;i<this.table_source_type_arr().length;i++){
    		  selectStr+="<option value="+i+">"+this.table_source_type_arr()[i]+"</option>";
    	  }
    	  selectStr+="</select>";
    	  $('div#easyui_dialog_source').dialog({
              modal: true,
              title: '请选择',
              width: "200",
              height: "150",
              closed: false,
              border:false,
              cache: false,
              content:"<div style='margin-left: 50px;margin-top: 50px;'>放在"+selectStr+"之前</div>",
              onClose : function() {  
            	  tbsourcefactoryColresizeEventForTwo.destroydialog();
              }
          });
    	}
    },
    /**选中某个物料放在哪个物料之前**/
    select_sort_material_type:function(self,colspan,defaulthouse){
    	this.select_sort_material_type_index=parseInt($(self).val());
    	//真正执行增加列
    	this.source_factory_add_y_then(colspan,defaulthouse);
    	this.select_sort_material_type_index=-1;//重置下标
    	tbsourcefactoryColresizeEventForTwo.destroydialog();
    },
    /**增加列 功能性修改 做过度功能
     * 由于增加了自定义顺序    */
    source_factory_add_y:function(colspan,defaulthouse){
    	if($("[name='checkbox_materialTypeSort']").get(0).checked) {
    		this.source_factory_add_y_sort_material_type(colspan,defaulthouse);
    	}else{
    		//没有自定义排序直接增加列
    		this.source_factory_add_y_then(colspan,defaulthouse);
    	}
    },
	/*增加列*/
    source_factory_add_y_then:function(colspan,defaulthouse){
    	//判断有没有子列为订单数 投料数 20180525
    	/*if(tbsourcefactoryColresizeEventForTwo.table_source_data().text=='投料数'){
    		if($("[name='order_s_small_feed_total']").length>0){
    			alert("已有投料数,请勿重复添加");
    			return;
    		}
    	}
    	if(tbsourcefactoryColresizeEventForTwo.table_source_data().text=='订单数'){
    		if($("[name='order_s_small_order_total']").length>0){
    			alert("已有订单数,请勿重复添加");
    			return;
    		}
    	}*/
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	
    	$(".source_factory_colresizeable_for_two")
    	console.info("source_factory_add_y");
    	if(colspan==100){//样式4 单列纵向
    		colspan=1;
    	}
    	this.index_y++;
    	if(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=undefined&&tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=-1){
    		//如果自定义
    		if(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index==0){//如果放在第一个
    			this.table_source_arr=[parseInt(colspan)].concat(this.table_source_arr);
    		}else{//当中
    			var firstArr=this.table_source_arr.slice(0,tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index);
    			var lastArr = this.table_source_arr.slice(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index);
    			this.table_source_arr=firstArr.concat([parseInt(colspan)]).concat(lastArr);
    		}
    	}else{
    		//默认最后添加
    		this.table_source_arr[this.index_y-1]=parseInt(colspan);
    	}
		var uniqueId= getuniqueId("uniqueid");
		this.last_uniqueId_for_template_card=uniqueId;
    	//this.uniqueId_arr[this.index_y-1]=uniqueId;
    	var td_uniqueId_arr = new Array(); 
    	/*给第一行tr添加相应td,保证colresize功能呢*/
    	for(var i=0;i<colspan;i++){
    		var td_uniqueId= getuniqueId("td_uniqueid");
    		td_uniqueId_arr[i]=td_uniqueId;
    		if(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=undefined&&tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=-1){//是否自定义选择排序
    			var indexSortDom = eval(tbsourcefactoryColresizeEventForTwo.table_source_arr.slice(0,tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index).join("+"));
				if(indexSortDom==undefined){indexSortDom=0}//放在第一个的时候
    			$(".source_factory_colresizeable_for_two").find("tr:first").find("td").eq(indexSortDom+1).before('<td uniqueid='+uniqueId+' td_uniqueid='+td_uniqueId+' style="height:0;width:50px;border:none;padding:0"></td>');
    		}else{
        		$(".source_factory_colresizeable_for_two").find("tr:first").append('<td uniqueid='+uniqueId+' td_uniqueid='+td_uniqueId+' style="height:0;width:50px;border:none;padding:0"></td>');
    		}
    	}
    	var rowspan=1;//列例如订单数 之类的 上下需合并 
    	/*添加列*/
    	$(".source_factory_colresizeable_for_two").find("tr:not(:first)").each(function(index,el){
    		if(index==0){/*第一行为序号*/
    			if(colspan==1){//colspan==1的时候 上下需要合并
    				rowspan=2;
    			}
    			//alert(rowspan)
        		var str='<td class="source_factory_colresizeable_td" colspan='+colspan+' rowspan='+rowspan+' uniqueid='+uniqueId+' >';
    			str+='<div class="source_factory_colresizeable_td_div_btn"><input type="button" style="position：absolute" value="删除列" onclick="tbsourcefactoryColresizeEventForTwo.source_factory_delete_y(this)">';
    			
    			if(rowspan==1){//不合并的列才能有物料类型 其余的合并只是作为展示
        			str+='<input type="button" style="" value="增加几列" onclick="tbsourcefactoryColresizeEventForTwo.add_y_byuniqueId_dialog(this)"></div>';
        			str+='<input type="text" hidden name="order_s_material_house" value="'+defaulthouse+'">';
        			str+='<input type="text" hidden name="order_s_isReadColor" value="'+tbsourcefactoryColresizeEventForTwo.table_source_data().isreadcolor+'">';
        			str+='<div class="source_factory_colresizeable_td_div" name="order_s_material_type">'+tbsourcefactoryColresizeEventForTwo.table_source_data().text+
        			'</div></td>';
    			}else{
    				str+='</div><input type="text" hidden name="order_s_material_house" value="'+defaulthouse+'">';
    				str+='<input type="text" hidden name="order_s_isReadColor" value="'+tbsourcefactoryColresizeEventForTwo.table_source_data().isreadcolor+'">';
    				str+='<div class="source_factory_colresizeable_td_div" name="order_s_material_type">'+tbsourcefactoryColresizeEventForTwo.table_source_data().text+
        			'</div></td>';
    			}
    			if(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=undefined&&tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=-1){
    				//物料类型那行 选中的无聊类型顺序 排除序号从0开始 要加上序号才是真正的Dom
    				$(this).find("td").eq(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index+1).before(str);
    			}else{
    				$(this).append(str);
    			}
    		}
    		if(index!=0){/*除去第一行为序号的其他列*/
    			/*默认三个name 色号 描述 规格*/
    			var default_name=["order_s_material_color","order_s_material_description","order_s_material_model"];
    			var default_name_text=["色号","颜色描述","规格型号"];
    			for(var i=0;i<colspan;i++){
    				console.info(rowspan);
    				if(index==1&&rowspan==2){
        				break;
        			}
    				var str='<td class="source_factory_colresizeable_td" uniqueid='+uniqueId+'  td_uniqueid='+td_uniqueId_arr[i]+'>';
    				if(index==1&&rowspan==1){
            			str+='<div class="source_factory_colresizeable_td_div_btn"><input type="button" btn_source_del_s_y_for_template_card style="position：absolute" value="删除子列" onclick="tbsourcefactoryColresizeEventForTwo.del_y_bytduniqueId(this)"></div>';
            			str+='<div class="source_factory_colresizeable_td_div">'+default_name_text[i]+'</div>';
    				}else{
    					if(rowspan==1){
    						str+='<div class="source_factory_colresizeable_td_div" name="'+default_name[i]+'" contenteditable="true"></div>';
    						if(i==0){/*物料代码存在在色号同级*/
    							str+='<input type="text" name="order_s_material_code" hidden/>';
    						}
    					}else{//合并的列通过localstorge中获取
    						//订单数 投料数 特殊处理
    						var name="order_s_material_model";
    						var text="";
    						if(tbsourcefactoryColresizeEventForTwo.table_source_data().text=="订单数"){
    							name="order_s_order_total";
    							text=0;
    						}
    						if(tbsourcefactoryColresizeEventForTwo.table_source_data().text=="投料数"){
    							name="order_s_feed_total";
    							text=0;
    						}
    						str+='<div class="source_factory_colresizeable_td_div" name="'+name+'" contenteditable="true">'+text+'</div>';
    					}
    				}
        			str+='</td>';
        			if(tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=undefined&&tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index!=-1){
        				if(index==1){
        					//下面小列
        					//由于物料列有合并情况 需要所有选中之前物料数之和 减去 所有第一行有上下和并列 不加一(因为序号上下合并)
        					var indexSortDom = eval(tbsourcefactoryColresizeEventForTwo.table_source_arr.slice(0,tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index).join("+"));
            				if(indexSortDom==undefined){indexSortDom=0}//放在第一个的时候
        					for(var j=0;j<tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index;j++){
            					var rowspanInt =$(".source_factory_colresizeable_for_two").find("[name='order_s_material_type']").eq(j).parents("td").attr("rowspan");
            					if(rowspanInt!="1"){
            						indexSortDom--;
            					}
            				}
        					//判断避免都是单列时候上下合并的情况 导致找不到节点
        					if($(this).find("td").eq(indexSortDom).length>0){
        						$(this).find("td").eq(indexSortDom).before(str);
        					}else{
        						//$(this).find("td").eq(indexSortDom-1).after(str);
        						$(this).append(str);//20200309
        					}
            			}else{
            				//所有选中之前物料数之和加1（序号）
        					var indexSortDom = eval(tbsourcefactoryColresizeEventForTwo.table_source_arr.slice(0,tbsourcefactoryColresizeEventForTwo.select_sort_material_type_index).join("+"));
        					if(indexSortDom==undefined){indexSortDom=0}//放在第一个的时候
        					$(this).find("td").eq(indexSortDom+1).before(str);
            			}
        			}else{
        				$(this).append(str);
        			}
    			}
    		}
    		
    	})
    	//bindEvent
    	tbsourcefactoryColresizeEventForTwo.bindEvent();
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    	//大货处理
    	if(tbsourcefactoryColresizeEventForTwo.table_source_data().text.indexOf("大货")>-1||tbsourcefactoryColresizeEventForTwo.table_source_data().text.indexOf("销售样")>-1){
    		this.smallY_dh(uniqueId);
    	}
    	return false;
    },
    /*增加列 第一次*/
    source_factory_add_y_first:function(colspan,defaulthouse){
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	
    	//$(".source_factory_colresizeable_for_two")
    	console.info("source_factory_add_y");
    	if(colspan==100){//样式4 单列纵向
    		colspan=1;
    	}
    	this.table_source_arr[this.index_y-1]=parseInt(colspan);
    	var uniqueId= getuniqueId("uniqueid");
    	//this.uniqueId_arr[this.index_y-1]=uniqueId;
    	var td_uniqueId_arr = new Array(); 
    	/*给第一行tr添加相应td,保证colresize功能呢*/
    	for(i=0;i<colspan;i++){
    		var td_uniqueId= getuniqueId("td_uniqueid");
    		td_uniqueId_arr[i]=td_uniqueId;
    		$(".source_factory_colresizeable_for_two").find("tr:first").append('<td uniqueid='+uniqueId+' td_uniqueid='+td_uniqueId+' style="height:0;width:50px;border:none;padding:0"></td>');
    	}
    	var rowspan=1;//列例如订单数 之类的 上下需合并 
    	/*添加列*/
    	$(".source_factory_colresizeable_for_two").find("tr:not(:first)").each(function(index,el){
    		if(index==0){/*第一行为序号*/
    			if(colspan==1){//colspan==1的时候 上下需要合并
    				rowspan=2;
    			}
    			//alert(rowspan)
        		var str='<td class="source_factory_colresizeable_td" colspan='+colspan+' rowspan='+rowspan+' uniqueid='+uniqueId+' >';
    			str+='<div class="source_factory_colresizeable_td_div_btn"><input type="button" style="position：absolute" value="删除列" onclick="tbsourcefactoryColresizeEventForTwo.source_factory_delete_y(this)">';
    			
    			if(rowspan==1){//不合并的列才能有物料类型 其余的合并只是作为展示
        			str+='<input type="button" style="" value="增加几列" onclick="tbsourcefactoryColresizeEventForTwo.add_y_byuniqueId_dialog(this)"></div>';
        			str+='<input type="text" hidden name="order_s_material_house" value="'+defaulthouse+'">';
        			str+='<input type="text" hidden name="order_s_isReadColor" value="'+tbsourcefactoryColresizeEventForTwo.table_source_data().isreadcolor+'">';
        			str+='<div class="source_factory_colresizeable_td_div" name="order_s_material_type">'+tbsourcefactoryColresizeEventForTwo.table_source_data().text+
        			'</div></td>';
    			}else{
    				str+='</div><input type="text" hidden name="order_s_material_house" value="'+defaulthouse+'">';
    				str+='<input type="text" hidden name="order_s_isReadColor" value="'+tbsourcefactoryColresizeEventForTwo.table_source_data().isreadcolor+'">';
    				str+='<div class="source_factory_colresizeable_td_div" name="order_s_material_type">'+tbsourcefactoryColresizeEventForTwo.table_source_data().text+
        			'</div></td>';
    			}
    			$(this).append(str);
    		}
    		if(index!=0){/*除去第一行为序号的其他列*/
    			/*默认三个name 色号 描述 规格*/
    			var default_name=["order_s_material_color","order_s_material_description","order_s_material_model"];
    			var default_name_text=["色号","颜色描述","规格型号"];
    			for(i=0;i<colspan;i++){
    				console.info(rowspan);
    				if(index==1&&rowspan==2){
        				break;
        			}
    				var str='<td class="source_factory_colresizeable_td" uniqueid='+uniqueId+'  td_uniqueid='+td_uniqueId_arr[i]+'>';
    				if(index==1&&rowspan==1){
            			str+='<div class="source_factory_colresizeable_td_div_btn"><input btn_source_del_s_y type="button" style="position：absolute" value="删除子列" onclick="tbsourcefactoryColresizeEventForTwo.del_y_bytduniqueId(this)"></div>';
            			str+='<div class="source_factory_colresizeable_td_div">'+default_name_text[i]+'</div>';
    				}else{
    					if(rowspan==1){
    						str+='<div class="source_factory_colresizeable_td_div" name="'+default_name[i]+'" contenteditable="true"></div>';
    						if(i==0){/*物料代码存在在色号同级*/
    							str+='<input type="text" name="order_s_material_code" hidden/>';
    						}
    					}else{//合并的列通过localstorge中获取
    						//订单数 投料数 特殊处理
    						var name="order_s_material_model";
    						var text="";
    						if(tbsourcefactoryColresizeEventForTwo.table_source_data().text=="订单数"){
    							name="order_s_order_total";
    							text=0;
    						}
    						if(tbsourcefactoryColresizeEventForTwo.table_source_data().text=="投料数"){
    							name="order_s_feed_total";
    							text=0;
    						}
    						str+='<div class="source_factory_colresizeable_td_div" name="'+name+'" contenteditable="true">'+text+'</div>';
    					}
    				}
        			str+='</td>';
            		$(this).append(str);
    			}
    		}
    		
    	})
    	//bindEvent
    	tbsourcefactoryColresizeEventForTwo.bindEvent();
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    	return false;
    },
    /*增加行*/
    source_factory_add_x:function (self){
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	var tr_uniqueid=getuniqueId("tr_uniqueid");/*获取相应唯一tr标识*/
    	this.index_x_no++;
    	var str='<tr class="source_factory_colresizeable_tr" tr_uniqueid="'+tr_uniqueid+'">'+
    				'<td>'+
    				'<div class="source_factory_colresizeable_td_div_btn"><input type="button" value="删除行" style="position：absolute" onclick="tbsourcefactoryColresizeEventForTwo.source_factory_delete_x(this)"></div>'+
    				'<div class="source_factory_colresizeable_td_div" name="order_s_line_no">'+this.index_x_no+'</div>'+
    				'</td>';
    	var td_index=1;//用于第一行的td_uniqueId 初始1 是排除行号的影响
    	for(i=0;i<this.index_y;i++){//有几列 
    		for(j=0;j<this.table_source_arr[i];j++){//每列几个td
    			var td_uniqueId = $(".source_factory_colresizeable_for_two").find("tr:first").find("td").eq(td_index).attr("td_uniqueid");
    			var name=$('[td_uniqueid="'+td_uniqueId+'"]').find("[name^='order_s_']").eq(0).attr("name");
    			var uniqueId = $(".source_factory_colresizeable_for_two").find("tr:first").find("td").eq(td_index).attr("uniqueid");
    			td_index++;
    			str+='<td class="source_factory_colresizeable_td" uniqueid='+uniqueId+' td_uniqueid='+td_uniqueId+'> ';
    			
        		str+='<div class="source_factory_colresizeable_td_div" contenteditable="true" name='+name+'>'+
    			'</div>';
    			if(name=="order_s_material_color"){
					str+='<input type="text" name="order_s_material_code" hidden/>';
    			}
    			'</td>';
    		}
    	}
    	str+='</tr>';
    	$(".source_factory_colresizeable_for_two").append(str);
    	//bindEvent
    	tbsourcefactoryColresizeEventForTwo.bindEvent()
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    	//大组件一存在的时候
    	if($(".source_factory_colresizeable").length>0){
    		//大组件一也要同步增加行
        	//大组件二自己增加行，如果大组件一行号大于大组件二行号 则 大组件二需要自己增加,增加到和大组件一一样的行号
        	if(tbsourcefactoryColresizeEvent.index_x_no>tbsourcefactoryColresizeEventForTwo.index_x_no){
        		tbsourcefactoryColresizeEventForTwo.source_factory_add_x();
        	}
        	//大组件二自己增加行如果大组件一行号小于大组件二行号 则 大组件需要自己增加
        	if(tbsourcefactoryColresizeEvent.index_x_no<tbsourcefactoryColresizeEventForTwo.index_x_no){
        		tbsourcefactoryColresizeEvent.source_factory_add_x();
        	}
    	}
    	return false;
    },
    /*删除列*/
    source_factory_delete_y:function(self){
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	this.index_y--;
    	//删除当前列table_source_arr
    	$(".source_factory_colresizeable_for_two").find("tr").eq(1).find("td").each(function(index,el){
    		if($(el).attr("uniqueid")==$(self).parent().parent().attr("uniqueid")){
    			tbsourcefactoryColresizeEventForTwo.table_source_arr.splice(index-1,1);
    		}
    	})
    	$("[uniqueid='"+$(self).parent().parent().attr("uniqueid")+"']").remove();
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    	return false;
    },
    /*删除行*/
    source_factory_delete_x:function(self){
    	if(this.index_x_no==1){return;}
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	this.index_x_no--;
    	$(self).parent().parent().parent().remove();
    	/*序号重新排版*/
    	$(".source_factory_colresizeable_for_two").find("[name='order_s_line_no']").each(function(index,el){
    		$(this).text(index+1);
    	})
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    	//物料大组件一也需要删除同样序号的行
    	if(tbsourcefactoryColresizeEvent.index_x_no!=tbsourcefactoryColresizeEventForTwo.index_x_no){
	    	var delLlineNo = $(self).parent().parent().find("[name='order_s_line_no']").text();
	    	$(".source_factory_colresizeable").find("[name='order_s_line_no']").each(function(index,el){
	    		if($(this).text()==delLlineNo){
	    			$(this).parent().find("input[type=button]").trigger("click");
	    			return false;
	    		}
	    	})
    	}
    },
    /*增加列 子项*/
    add_y_byuniqueId:function(uniqueid,y_num,data){
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	console.info("add_y_byuniqueId");
    	console.info(uniqueid+":"+y_num);
    	console.info(data);
    	var td_uniqueId_arr=new Array();
    	for(i=0;i<y_num;i++){
    		td_uniqueId_arr[i]=getuniqueId("td_uniqueid");
    	}
    	$(".source_factory_colresizeable_for_two").find("tr").each(function(index,el){
    		if(index==0){//第一行tr增加相应的列 为了colresize功能
        		for(i=0;i<y_num;i++){
        			$(this).find("[uniqueid='"+uniqueid+"']:last").after(
        					'<td uniqueid='+uniqueid+' td_uniqueid='+td_uniqueId_arr[i]+' style="height:0;width:50px;border:none;padding:0"></td>');
        		}
    		}
    		if(index==1){
    			var colspan_new = parseInt($(this).find("[uniqueid='"+uniqueid+"']").attr("colspan"))+parseInt(y_num);
    			$(this).find("[uniqueid='"+uniqueid+"']").attr("colspan",colspan_new);
    		}
    		if(index>1){//从第3行开始每行增加相应的y_num 和 数据
    			for(i=0;i<y_num;i++){
    				var str_diff= '<div class="source_factory_colresizeable_td_div_btn"><input type="button" style="position：absolute" value="删除子列" onclick="tbsourcefactoryColresizeEventForTwo.del_y_bytduniqueId(this)"></div>'+
					   '<div class="source_factory_colresizeable_td_div">'+data[i].text+'</div>';
    				if(data[i].domName!=undefined){//为了特殊的 例如大货时间
    					str_diff= '<div class="source_factory_colresizeable_td_div_btn"><input type="button" style="position：absolute" value="删除子列" onclick="tbsourcefactoryColresizeEventForTwo.del_y_bytduniqueId(this)"></div>'+
 					   '<div class="source_factory_colresizeable_td_div" name="'+data[i].domName+'">'+data[i].text+'</div>';
    				}
    				
    				if(index!=2){
    					str_diff='<div class="source_factory_colresizeable_td_div" contenteditable="true" name="'+data[i].html_name+'"></div>';
    					if(data[i].html_name=="order_s_material_color"){//添加色号 需要增加物料代码
    						str_diff+='<input type="text" name="order_s_material_code" hidden>';
    					}
    				}
    				$(this).find("[uniqueid='"+uniqueid+"']:last").after(
    						'<td class="source_factory_colresizeable_td" uniqueid='+uniqueid+' td_uniqueid='+td_uniqueId_arr[i]+'> '+
    						str_diff+	
        	    			'</td>'
    				);
    			}
    		}
    	});
    	//修改table_source_arr
    	$(".source_factory_colresizeable_for_two").find("tr").eq(1).find("td").each(function(index,el){
    		if($(el).attr("uniqueid")==uniqueid){
    			var num_new = parseInt(tbsourcefactoryColresizeEventForTwo.table_source_arr[index-1])+parseInt(y_num);
    			tbsourcefactoryColresizeEventForTwo.table_source_arr[index-1]=num_new;
    		}
    	})
    	//bindEvent
    	tbsourcefactoryColresizeEventForTwo.bindEvent();
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    },
    /*删除列 子项*/
    del_y_bytduniqueId(self){
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:true
        });
    	//获取td_uniqueid
    	var td_uniqueid = $(self).parent().parent().attr("td_uniqueid");
    	var uniqueid = $(self).parent().parent().attr("uniqueid");
    	//修改列合并数目
    	$("[uniqueid='"+uniqueid+"']").each(function(){
    		 if(typeof($(this).attr("colspan"))!="undefined"){
    			 var colspan_new = parseInt($(this).attr("colspan"))-1;
    			 $(this).attr("colspan",colspan_new);
    		 }
    	})
    	//删除该列
    	$("[td_uniqueid='"+td_uniqueid+"']").remove();
    	//修改table_source_arr
    	$(".source_factory_colresizeable_for_two").find("tr").eq(1).find("td").each(function(index,el){
    		if($(el).attr("uniqueid")==$(self).parent().parent().attr("uniqueid")){
    			var num_new = parseInt(tbsourcefactoryColresizeEventForTwo.table_source_arr[index-1])-1;
    			if(num_new==0){
    				tbsourcefactoryColresizeEventForTwo.table_source_arr.splice(index-1,1);
    			}else{
        			tbsourcefactoryColresizeEventForTwo.table_source_arr[index-1]=num_new;
    			}
    		}
    	})
    	//如果第一行没有uniqueid则干掉所有uniqueid
    	var tr_fist_td_uniqueid_total=$(".source_factory_colresizeable_for_two").find("tr:first").find("[uniqueid='"+uniqueid+"']").length;
    	if(tr_fist_td_uniqueid_total==0){
    		$("[uniqueid='"+uniqueid+"']").remove();
    		this.index_y--;
    	}
    	$(".source_factory_colresizeable_for_two").colResizable({
			disable:false
        });
    	this.reload_first_w();
    },//子列选择
    add_y_byuniqueId_dialog:function(self){
    	var uniqueid = $(self).parent().parent().attr("uniqueid");
		var tr_uniqueid = $(self).parent().parent().parent().attr("tr_uniqueid");
		var has_small_y = $(".source_factory_colresizeable_for_two").find("tr").eq(2).find('[uniqueid="'+uniqueid+'"]').find("div").map(function(){return $(this).text()}).get();
    	$('div#easyui_dialog_source').dialog({
            modal: true,
            title: '请选择',
            width: "550",
            height: "400",
            closed: false,
            border:false,
            cache: false,
            content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='source_factory_colresize_addy_dialog_for_two.html?uniqueid="+uniqueid+"&tr_uniqueid="+tr_uniqueid+"&ev="+name+"&has_small_y="+has_small_y+"'></iframe>",
            onClose : function() {  
            	tbsourcefactoryColresizeEventForTwo.destroydialog();
            }
        });
    },//重新刷新第一条tr的宽度
    reload_first_w:function(){
    	var width = $(".source_factory_colresizeable_for_two").parent().parent().width()/($(".source_factory_colresizeable_for_two").find("tr").eq(0).find("td").length);
    	$(".source_factory_colresizeable_for_two").find("tr").eq(0).find("td").each(function(index,el){
    		$(".source_factory_colresizeable_for_two").parent().find(".JCLRgrip").eq(index).css({"left":width*(index+1)});
    		$(this).width(width);
    	})
    	//订单数和投料数绑定事件
    	UtilForEveryAreaEvent.orderTotalFeedTotal_blur();
    	//增加table刷新功能
    	menubuttonIndexTool.refreshMaterialTable();
    },//通过物料类型统计投料数
    sumFeedTotalByMaterialType:function(str){
    	return;//暂时禁用 计算投料数错误
    	var feedTotal=0;
    	if(str!=null){
    		$(".source_factory_colresizeable_for_two").find("[name='order_s_material_type']").each(function(){
        		if(str.indexOf($(this).text())>-1){
        			var uniqueid = $(this).parent().attr("uniqueid");
        			if($("[uniqueid='"+uniqueid+"']").find("[name='order_s_small_feed_total']").length>0){//存在小列投料数
        				$("[uniqueid='"+uniqueid+"']").find("[name='order_s_small_feed_total']").each(function(){
                			feedTotal+=parseInt($(this).text());
                		})
        			}else{
        				$(".source_factory_colresizeable_for_two").find("[name='order_s_feed_total']").each(function(){
                			feedTotal+=parseInt($(this).text());
                		})
        			}
        		}
        	})
    	}
    	$(".source_factory_colresizeable_for_two").find("[name='order_p_feed_total']").val(feedTotal);
    },
    feedTotalBlur:function(){
    	var smallFeedTotal=0
    	$(".source_factory_colresizeable_for_two").find('tr').each(function(){
    		var every_tr_smallFeedTotal=0;
    		$(this).find("[name='order_s_small_feed_total']").each(
    				function(index,el){
    					if(index==0){
    						every_tr_smallFeedTotal=parseInt($(this).text().length>0?$(this).text():0);
    					}
    					if(every_tr_smallFeedTotal>parseInt($(this).text().length>0?$(this).text():0)){//取每一行小的
    						every_tr_smallFeedTotal=parseInt($(this).text().length>0?$(this).text():0);
    					}
    		});
    		smallFeedTotal+=every_tr_smallFeedTotal;
    		}
    	)
    	var feed_total=0;
    	$(".source_factory_colresizeable_for_two").find("[name='order_s_feed_total']").each(function(i,elem){
        	feed_total+=parseInt($(this).text().length>0?$(this).text():0);
        })
        if(isNaN(smallFeedTotal)){smallFeedTotal=0}
        if(isNaN(feed_total)){feed_total=0}
        $(".source_factory_colresizeable_for_two").find("[name='order_p_feed_total']").val((smallFeedTotal!=0)?smallFeedTotal:feed_total);
    	return (smallFeedTotal!=0)?smallFeedTotal:feed_total;
    },
    //在序号中添加物料代码
    addMaterialCodeForLineNo:function(_tr_uniqueid,_material_source_type,_material_house,_materialCode){
		var _dom = $(".source_factory_colresizeable_for_two").find("[tr_uniqueid='"+_tr_uniqueid+"']").find("[name='order_s_line_no']");
		console.info($(".source_factory_colresizeable_for_two").find("[tr_uniqueid='"+_tr_uniqueid+"']").find("[name='order_s_line_no']").length)
		$.data(_dom[0],_material_source_type+"|"+_material_house,_materialCode);
		console.info($.data(_dom[0]));
    },
    //在序号中获取物料代码
    getMaterialCodeForLineNo:function(_tr_uniqueid,_material_source_type,_material_house,_materialCode){
		var _dom = $(".source_factory_colresizeable_for_two").find("[tr_uniqueid='"+_tr_uniqueid+"']").find("[name='order_s_line_no']");
		return $(_dom).data(_material_source_type+"|"+_material_house);
    },
    isReadColorFix:function(){
    	//是否读取颜色
    	var str_isReadColor = `<input type="text" hidden name="order_s_isReadColor" value="">`;
    	$(".source_factory_colresizeable_for_two").find("[name='order_s_material_type']").each(function(index,el){
    		if($(this).parent().find('[name="order_s_isReadColor"]').length<1){
    			$(this).after(str_isReadColor);
    		}
    	})
    },
    checkLineNoTotalIsMatchHtmlLineTotal:function(lineNoTotal){
    	var diffTotal = lineNoTotal-tbsourcefactoryColresizeEventForTwo.index_x_no;
    	//校验数据中的行号和模板的行号是否匹配
    	if(!isNaN(lineNoTotal)&&lineNoTotal>tbsourcefactoryColresizeEventForTwo.index_x_no){
    		//是数字并且比模板行号多
    		for(var index=0;index<diffTotal;index++){
    			//增加行动作
    			tbsourcefactoryColresizeEventForTwo.source_factory_add_x();
    		}
    	}
    },
    //大货特殊处理
    smallY_dh:function(uniqueId){
    	//同一个uniqueId下的增加小列
    	this.add_y_byuniqueId(uniqueId,1,[{"html_name": "order_s_dh_total",
    		"domName":"special_dh_date",
    		"id": 999,
    		"special_val": 0,
    		"text": utilgetFormatDate("yyyy-MM-dd")}]);
    	//然后删除前面的所有的小列
    	$("[uniqueid='"+uniqueId+"']").find(".source_factory_colresizeable_td_div_btn").not(":last").each(function(){
    		if($(this).find("input[type=button]").val()=="删除子列"){
    			$(this).find("input[type=button]").click();
    		}
    	})
    	//隐藏删除子列按钮
    	$("[uniqueid='"+uniqueId+"']").find(".source_factory_colresizeable_td_div_btn").find("input[type=button]").each(function(){
    		if($(this).val()=="删除子列"||$(this).val()=="增加几列"){
    			$(this).hide();
    		}
    	})
    	//绑定大货时间事件
    	this.bindDhDateEvent();
    },
    //绑定大货时间事件
    bindDhDateEvent:function(){
    	$("[name='special_dh_date']").unbind("click");
    	$("[name='special_dh_date']").bind("click",function(){
    		var uniqueid = $(this).parent().attr("uniqueid");
			var td_uniqueid = $(this).parent().attr("td_uniqueid");
			var tr_uniqueid = $(this).parent().parent().attr("tr_uniqueid");
			var material_source_type = $("[uniqueid='"+uniqueid+"']").find("[name='order_s_material_type']").text();
			var name=$(this).attr("name");
			$('div#easyui_dialog_source').dialog({
                modal: true,
                title: '请选择',
                width: "200",
                height: "300",
                closed: false,
                border:false,
                cache: false,
                content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='time_dialog.html?material_source_type="+material_source_type+"&uniqueid="+uniqueid+"&td_uniqueid="+td_uniqueid+"&tr_uniqueid="+tr_uniqueid+"&ev="+name+"'></iframe>",
                onClose : function() {  
                	tbsourcefactoryColresizeEventForTwo.destroydialog();
                }
            });
    	});
    }
}

tbsourcefactoryColresizeEventForTwo.bindEvent();
tbsourcefactoryColresizeEventForTwo.table_source_arr_for_temp();
tbsourcefactoryColresizeEventForTwo.isReadColorFix();

